 //
//  MPFImageCell.m
//  MPTUILibrary
//
//  Created by jiaxuzhou on 2017/7/25.
//  Copyright © 2017年 蔡勋. All rights reserved.
//


#import "MPFImageCell.h"
#import "MPCImageView.h"
#import "MPCButton.h"


@interface MPFImageCell ()
{
    MPCImageView *imgvBg;
    MPCButton *btnBg;
}

@end


@implementation MPFImageCell


#pragma mark - ********************** View Lifecycle **********************

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self)
    {
        // 创建cell的subview
        [self initCellContent];
        
        // 注册消息
        [self regNotification];
    }
    
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    imgvBg.frame = CGRectMake(0, 0, self.contentView.width, self.contentView.height);
    
    btnBg.frame = CGRectMake(0, 0, self.contentView.width, self.contentView.height);

    
}


#pragma mark - ********************** init and config **********************

/**
 创建cell所包含的subviews
 */
- (void)initCellContent
{
//    imgvBg = [MPCImageView getWithFrame:CGRectMake(0, 0, self.contentView.width, self.contentView.height)];
//    imgvBg.backgroundColor = [UIColor whiteColor];
//    imgvBg.imagePlaceholder([UIImage imageNamed:@"bg_pic"]);
//    [self.contentView addSubview:imgvBg];
    
    btnBg = [MPCButton getWithFrame:CGRectMake(0, 0, self.contentView.width, self.contentView.height) target:self action:@selector(btnClick)];
    btnBg.backgroundColor = [UIColor whiteColor];
    btnBg.imagePlaceholder([UIImage imageNamed:@"bg_pic"]);
    [self.contentView addSubview:btnBg];

    
}

- (void)btnClick
{
    NSLog(@"click");
}

#pragma mark - ******************************************* 对外方法 *********************************

/**
 设置cell内subview的内容和frame
 */
- (void)setCellContent:(NSString *)imgUrl
{
//    imgUrl = @"http://bsyimg4.cdn.krcom.cn/stream/yRWwBSLX9ZMwC07jk79WJSxpMdsmu86T_crd3_4.jpg";
    
    [btnBg mp_setImageWithURL:imgUrl options:0 success:^(UIImage * _Nullable image, NSURL * _Nullable url, MPWebImageFromType from, MPWebImageStage stage)
     {
         NSLog(@"%@   %d",image,stage);
        
    } fail:^(NSURL * _Nullable url, MPWebImageFromType from, MPWebImageStage stage, NSError * _Nullable error)
     {
         NSLog(@"");

    }];
    
//    imgUrl = [imgUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:@"`#%^{}\"[]|\\<> "].invertedSet];
//
//    
//    [imgvBg sd_setImageWithURL:[NSURL URLWithString:imgUrl]  completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL)
//    {
//        NSLog(@"dddddd");
//    }];
    
}

/**
 获取cell的高度
 
 @return 返回cell的高度
 */
+ (CGFloat)getCellHeight
{
    return 0;
}


#pragma mark - ******************************************* 基类方法(一般发生在重写函数) ****************


#pragma mark - ******************************************* Touch Event ***********************

/**
 TODO: 返回按钮点击事件的响应函数
 
 @param sender 被点击的按钮
 */
- (void)btnClickBack:(UIButton *)aSender
{
    
}


#pragma mark - ******************************************* 私有方法 **********************************

/**
 TODO: 注册消息
 */
- (void)regNotification
{
    
}


#pragma mark - ******************************************* Net Connection Event ********************

#pragma mark - 请求 demo

- (void)req_url_demo
{
    
}


#pragma mark - ******************************************* Delegate Event **************************

#pragma mark - 代理 demo

- (void)delegate_demo
{
    
}


#pragma mark - ******************************************* Notification Event **********************

#pragma mark - 通知 demo

- (void)notification_demo:(NSNotification *)aNotification
{
    
}


#pragma mark - ******************************************* 属性变量的 Set 和 Get 方法 *****************


@end
